package cn.xopencode.appletweb.controller.permission;

import cn.xopencode.common.framework.util.StringUtils;
import cn.xopencode.common.framework.vo.CommonResult;
import cn.xopencode.oss.rpc.permission.PermissionRpc;
import cn.xopencode.oss.rpc.permission.dto.PermissionAssignEmployeePositionDTO;
import cn.xopencode.oss.rpc.permission.dto.PermissionAssignPositionResourceDTO;
import cn.xopencode.security.annotations.RequiresNone;
import cn.xopencode.security.annotations.RequiresPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static cn.xopencode.common.framework.vo.CommonResult.success;
import java.util.Arrays;
import java.util.Set;
import java.util.TreeSet;

@Api(tags = "职务权限 API")
@RestController
@RequestMapping("/permission")
public class PermissionController {
    @DubboReference(version = "${dubbo.consumer.PermissionRpc.version}")
    private PermissionRpc permissionRpc;
    @GetMapping("/list-position-resources")
    @ApiOperation("获得职位拥有的资源ID")
    @ApiImplicitParam(name = "positionId", value = "职位ID", required = true)
    //@RequiresPermissions("oss:permission:list-position-resource")
    @RequiresNone
    public CommonResult<Set<String>> listPositionResources(String positionId) {
        Set<String> positionResourceIds= new TreeSet<>();
        for(int i=0;i<100;i++){
            positionResourceIds.add(StringUtils.uuid(true));
        }
        return success(positionResourceIds);
    }

    @PostMapping("/assign-role-resource")
    @ApiOperation("授予职位资源")
    @RequiresNone
    //@RequiresPermissions("oss:permission:assign-position-resource")
    public CommonResult<Boolean> assignPositionResource(PermissionAssignPositionResourceDTO assignPositionResourceDTO) {
        return success(true,"ID为"+assignPositionResourceDTO.getPositionId()+"的职位授予权限资源成功");
    }

    @PostMapping("/assign-employee-position")
    @ApiOperation("授予用户职位")
    @RequiresNone
    //@RequiresPermissions("oss:permission:assign-employ-position")
    public CommonResult<Boolean> assignEmployeeRole(PermissionAssignEmployeePositionDTO assignEmployeePositionDTODTO) {
        return success(true,"员工授予职位"+assignEmployeePositionDTODTO.getPositionId()+"成功");
    }
}
